package com.ssy.lingxi.product.common.enums;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.Objects;

/**
 * 物料流程状态适用类型定义
 * @author pengdd
 * @version 2.0.0
 * @date 2022/3/24
 */
public enum MaterialProcessSuitableTypeEnum {

    ALL(1, "所有物料"),
    GROUP(2, "选择部分物料组"),
    MATERIAL(3, "选择部分物料"),
    UNKNOWN(999, "未知")
    ;
    private final Integer code;
    private final String message;
    MaterialProcessSuitableTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getMessage(Integer code) {
        return Arrays.stream(MaterialProcessSuitableTypeEnum.values()).filter(f -> Objects.equals(f.getCode(), code)).findFirst().map(MaterialProcessSuitableTypeEnum::getMessage).orElse("");
    }

    public static MaterialProcessSuitableTypeEnum getEnum(Integer code) {
        return Arrays.stream(MaterialProcessSuitableTypeEnum.values()).filter(f -> Objects.equals(f.getCode(), code)).findFirst().orElse(UNKNOWN);
    }
}
